<? /* mysql 추가함수 그룹*/ function sqlFetchArrayQ($sql) { $result = mysql_query($sql);
 $row = mysql_fetch_array($result);
 if(mysql_errno() > 0) echo "원문: ".$sql."<br/>";
 return $row;
 } function sql_resultMsg($errno, $errorMsg) { if($errno > 0) { echo $errorMsg;
 exit;
 } else { /*echo "<script>alert('정상 처리되었습니다.\\t');
</script>";
*/ } } /* 권한 그룹*/ function admin_check() { global $is_admin;
 if($is_admin != "super") alert("관리자만 접근가능합니다.\\t", "./");
 } /* get 그룹*/ function get_bigName($bigCode) { $sql = "select big_name from qpass_catBig where big_code = '$bigCode' ";
 list($bigName) = sqlFetchArrayQ($sql);
 return $bigName;
 } function get_midName($midCode) { $sql = "select mid_name from qpass_catMid where mid_code = '$midCode' ";
 list($midName) = sqlFetchArrayQ($sql);
 return $midName;
 } function get_smallName($small_code) { $sql = "select small_name from qpass_catSmall where small_code = '$small_code' ";
 list($examName) = sqlFetchArrayQ($sql);
 return $examName;
 } function get_examName($uid) { $sql = "select exam_name from qpass_exam where uid = '$uid' ";
 list($examName) = sqlFetchArrayQ($sql);
 return $examName;
 } function get_examComment($uid) { $sql = "select exam_comment from qpass_exam where uid = '$uid' ";
 list($exam_comment) = sqlFetchArrayQ($sql);
 return $exam_comment;
 } function get_catSubject($examUid, $cat_index) { $i_add = $cat_index + 1;
 if($i_add < 10) $i_add = "0".$i_add;
 $catTitle = "cat_title".$i_add;
 $sql = "select $catTitle from qpass_exam where uid = '$examUid' ";
 list($catTitle) = sqlFetchArrayQ($sql);
 return $catTitle;
 } function get_qpass_bigCat($bigCode) { $sql = "select * from qpass_catBig order by big_code";
 $result = mysql_query($sql);
 $optionText = "";
 while( $row = mysql_fetch_array($result) ) {  if($bigCode == $row[big_code]) $optionText .= "<option value='$row[big_code]' selected>$row[big_name]</option>";
 else $optionText .= "<option value='$row[big_code]'>$row[big_name]</option>";
 } return $optionText;
 } function get_qpass_midCat($bigCode, $midCode) { if($bigCode == "") return;
 $sql = "select * from qpass_catMid where left(mid_code, 2) = '$bigCode' order by mid_code";
 $result = mysql_query($sql);
 $optionText = "";
 while( $row = mysql_fetch_array($result) ) {  if($midCode == $row[mid_code]) $optionText .= "<option value='$row[mid_code]' selected>$row[mid_name]</option>";
 else $optionText .= "<option value='$row[mid_code]'>$row[mid_name]</option>";
 } return $optionText;
 } function get_qpass_smallCat($midCode, $smallCode) { if($midCode == "") return;
 $sql = "select * from qpass_catSmall where left(small_code, 4) = '$midCode' order by small_code";
 $result = mysql_query($sql);
 $optionText = "";
 while( $row = mysql_fetch_array($result) ) {  if($smallCode == $row[small_code]) $optionText .= "<option value='$row[small_code]' selected>$row[small_name]</option>";
 else $optionText .= "<option value='$row[small_code]'>$row[small_name]</option>";
 } return $optionText;
 } function get_examOptions($small_code, $examUid, $asc) { if($small_code == "") return;
 $selectText = "";
 $sql = "select uid, exam_name from qpass_exam where small_code = '$small_code' order by uid $asc";
 $result = mysql_query($sql);
 while( $row = mysql_fetch_array($result) ) {  if($examUid == $row[uid]) $selectText .= "<option value='$row[uid]' selected>$row[exam_name]</option>";
 else $selectText .= "<option value='$row[uid]'>$row[exam_name]</option>";
 } return $selectText;
 } function get_examCatOptions($examUid, $selectedIndex) { if($examUid == "") return;
 $selectText = "";
 $sql = "select * from qpass_exam where uid = '$examUid'";
 $result = mysql_query($sql);
 $row = mysql_fetch_array($result);
 if(!$row[cat_countTotal]) return;
 for($i=1;
 $i <= $row[cat_countTotal];
 $i++) { $i_add = $i;
 $i_minus = $i - 1;
 if($i_add < 10) $i_add = "0".$i_add;
 $catTitle = $row["cat_title".$i_add];
 if($catTitle && $selectedIndex != '' && $i_minus == $selectedIndex)  $selectText .= "<option value='$i_minus' selected>$catTitle</option>";
 else  $selectText .= "<option value='$i_minus'>$catTitle</option>";
 } return $selectText;
 } function get_examCat($examUid, $selectedValue) { if($examUid == "") return;
 $sql = "select * from qpass_exam where uid = '$examUid' ";
 if($examCat == "") $selectText = "<option value=''>과목없음</option>";
 else { $selectText = "<option value=''>선택하세요</option>";
 $catList = explode("|", $examCat);
 for($i=0;
 $i < sizeof($catList);
 $i++) { if( $selectedValue && trim($catList[$i]) == trim($selectedValue) )  $selectText .= "<option value='$catList[$i]' selected>$catList[$i]</option>";
 else  $selectText .= "<option value='$catList[$i]'>$catList[$i]</option>";
 } } return $selectText;
 } function get_examCorrectCount($examUid, $catCount, $mb_id) { $sql = "select * from qpass_result where exam_uid = '$examUid' and mb_id = '$mb_id' ";
  $result = mysql_query($sql);
 $row = mysql_fetch_array($result);
 $countTotal = 0;
 for($i=1;
 $i <= $catCount ;
 $i++) { $i_add = $i;
 if($i_add < 10) $i_add = "0".$i_add;
  $tryStr = $row["try_list".$i_add];
 $eachCount = get_correctCount($tryStr, $examUid, $i-1);
 /*echo "count: $eachCount ";
 exit;
*/ if($eachCount > 0) $countTotal += $eachCount;
 }  return $countTotal;
 } function get_correctCount($tryStr, $examUid, $catIndex) { /* 답안 리스트 추출*/ $tryList = explode("|Q|", $tryStr);
 /* 정답 리스트 추출*/ $sql = "select answer from qpass_question where exam_uid = '$examUid' and cat_index = '$catIndex' order by view_index asc, uid asc";
 /*echo $sql .$tryStr;
*/ $resultAns = mysql_query($sql);
 $i = 0;
 $correctCount = 0;
 while( $rowAns = mysql_fetch_array($resultAns) ) { /*echo $i." : ".$rowAns[answer]." and ".$tryList[$i]."<br/>";
*/ $answer = str_replace(" ", "", $rowAns[answer]);
 $ansTry = str_replace(" ", "", $tryList[$i++]);
 if($ansTry == "") continue;
  if( $answer == $ansTry ) $correctCount++;
 else if( ereg(",", $answer) ) { $ansList = explode(",", $answer);
 for($j=0;
 $j < sizeof($ansList);
 $j++) { $answerEach = str_replace(" ", "", $ansList[$j]);
 if($answerEach == $ansTry) $correctCount++;
   /*echo "answerEach : $answerEach<br/>";
 */ } } } return $correctCount;
 } /* print 그룹*/ function print_question_list_adm($small_code, $examUid, $selectedIndex, $questionUid) { global $question_listCount, $currentPage;
 if(!$currentPage) $currentPage = 1;
 $sql_add = "";
 if($selectedIndex != '') $sql_add = "and q.cat_index = '$selectedIndex' ";
 if($examUid) {  $sql = "select q.* ";
 $common_sql = "from qpass_question q where q.exam_uid = '$examUid' $sql_add order by q.cat_index, q.view_index, q.uid";
 } else {  $sql = "select q.*, e.uid as examUid ";
 $common_sql = "from qpass_exam e, qpass_question q where e.uid=q.exam_uid and e.small_code = '$small_code' $sql_add order by e.uid, q.cat_index, q.view_index, q.uid";
 }  $count_sql = "select count(*) ".$common_sql;
 /*echo $count_sql;
*/ list($totalLine) = sqlFetchArrayQ($count_sql);
 $startLine = ($currentPage-1) * $question_listCount;
 $sql .= $common_sql." limit $startLine, $question_listCount";
 /*echo $sql." and $startLine";
*/ $result = mysql_query($sql);
 $row = mysql_fetch_array($result);
 echo "<table width='800' align='center' cellpadding='3' cellspacing='1' style='margin-top:3px;
 background-color:#ccc' border='0'>";
 echo "<tr style='background-color:white'>";
 echo "<td width='30' class='title02_qpass'>순서</td>";
 echo "<td width='100' class='title02_qpass'>시험명</td>";
 echo "<td width='80' class='title02_qpass'>과목명</td>";
 echo "<td width='' class='title02_qpass'>문 제</td>";
 echo "<td width='60' class='title02_qpass'>우선순위</td>";
 echo "<td class='title02_qpass'>처리</td>";
 echo "</tr>";
  if(!$row) { $smallName = get_smallName($small_code);
 echo "<tr height='100' style='background-color:white'><td colspan='6' align='center'><span style='color:#bb0000'>등록된 문제가 없습니다.</span></td></tr></table>";
  return;
 } $lineCount = 1;
 $revCount = $totalLine - $startLine;
 do { if($questionUid == $row[uid]) {  $lineColor = ";
 color:blue";
 } else $lineColor = "";
  if($row[examUid]) $examUid = $row[examUid];
 $examName = get_examName($examUid);
 $catSubject = get_catSubject($examUid, $row[cat_index]);
 if($catSubject == "") $catSubject = "&nbsp;
";
 $questionText = "<a href='admin_question.php?questionUid=$row[uid]' onfocus='this.blur()' style='$lineColor'>".$row[question]."</a>";
 $indexText = "<input type='text' name='view_index{$row[uid]}' maxlength='5' value='$row[view_index]' class='ed' style='width:30;
 text-align:center $lineColor'>";
 $processText = "<input type='button' value='수정' class='btn02_qpass' style='$lineColor' onclick=\"question_modify('$row[uid]')\" onfocus='this.blur()'>";
 $processText .= " &nbsp;
<input type='button' value='삭제' class='btn02_qpass' style='$lineColor' onclick=\"question_delete('$row[uid]')\" onfocus='this.blur()'>";
 echo "<tr style='background-color:white'>";
 echo "<td align='center' style='$lineColor'>$revCount</td>";
 echo "<td align='center'><a href='admin_exam.php?examUid=$examUid' style='$lineColor'>$examName</a></td>";
 echo "<td align='center' style='$lineColor'>$catSubject</td>";
  echo "<td width=''>$questionText</td>";
  echo "<td width='' align='center'>$indexText</td>";
  echo "<td width='80' align='center'>$processText</td>";
 echo "</tr>";
 $lineCount++;
 $revCount--;
 } while( $row = mysql_fetch_array($result) );
 echo "</table>";
 print_qpass_pages($totalLine, $question_listCount, $currentPage, "&small_code=$small_code&examUid=$_GET[examUid]&cat_index=$selectedIndex");
 } function print_qpass_examList_adm($smallCode, $view_line, $uid) { global $currentPage;
 if(!$currentPage) $currentPage = 1;
 $common_sql = "from qpass_exam where small_code = '$smallCode' order by uid desc";
 $count_sql = "select count(*) ".$common_sql;
 /*echo $count_sql;
*/ list($totalLine) = sqlFetchArrayQ($count_sql);
 $startLine = ($currentPage-1) * $view_line;
 $lineCount = 1;
 $sql = "select * ".$common_sql." limit $startLine, $view_line";
 /*echo $sql;
*/ $resultExam = mysql_query($sql);
 $rowExam = mysql_fetch_array($resultExam);
  /* 제목라인*/ echo "<table width='700' align='center' cellpadding='3' cellspacing='1' style='margin:15px 0 10px 0;
 background-color:#ccc' border='0'>";
 echo "<tr style='background-color:white'>";
 echo "<td width='30' class='title02_qpass'>순서</td>";
 echo "<td width='' class='title02_qpass'>시험명</td>";
 echo "<td width='100' class='title02_qpass'>등록일시</td>";
 echo "<td width='40' class='title02_qpass'>문제수</td>";
 echo "<td width='80' class='title02_qpass'>시험노출</td>";
 echo "<td class='title02_qpass'>처리</td>";
 echo "</tr>";
 if($rowExam == "") { echo "<tr height='100' style='background-color:white'> <td colspan='6' align='center' style='color:#bb0000'>등록된 시험이 없습니다. </td> </tr> </table>";
 return;
 } $revCount = $totalLine - $startLine;
 do { if($uid == $rowExam[uid]) {  $lineColor = ";
 color:blue";
 } else $lineColor = "";
 $sql = "select count(*) from qpass_question where exam_uid = '$rowExam[uid]' ";
 list($questionCount) = sqlFetchArrayQ($sql);
 $viewText = "<select id='view_ox{$rowExam[uid]}' style='$lineColor'>";
 if($rowExam[view_ox] == 1) $viewText .= "<option value='1' selected>예</option> <option value='-1'>아니오</option></select>";
 else if($rowExam[view_ox] == -1) $viewText .= "<option value='1'>예</option> <option value='-1' selected>아니오</option></select>";
 $processText = "<input type='button' value='수정' class='btn02_qpass' style='$lineColor' onclick=\"exam_modify('$rowExam[uid]')\" onfocus='this.blur()'>";
 $processText .= " &nbsp;
<input type='button' value='삭제' class='btn02_qpass' style='$lineColor' onclick=\"exam_delete('$rowExam[uid]')\" onfocus='this.blur()'>";
 $processText .= " &nbsp;
<input type='button' value='문제관리' class='btn02_qpass' style='$lineColor' onclick=\"location.href='admin_question.php?examUid=$rowExam[uid]'\" onfocus='this.blur()'>";
 echo "<tr style='background-color:white'>";
 echo "<td align='center' style='$lineColor'>$revCount</td>";
 echo "<td><a href='admin_exam.php?uid=$rowExam[uid]' style='$lineColor'>$rowExam[exam_name]</a></td>";
 echo "<td align='center' style='$lineColor'>".substr($rowExam[reg_time], 0,16)."</td>";
 echo "<td align='center' style='$lineColor'>$questionCount</td>";
 echo "<td align='center'>$viewText</td>";
 echo "<td align='center' width='140'>$processText</td>";
 echo "</tr>";
 $revCount--;
 } while( $rowExam = mysql_fetch_array($resultExam) );
 echo "</table>";
 print_qpass_pages($totalLine, $view_line, $currentPage, "exam");
 return;
 } function print_qpass_examList($targetCode, $viewLine, $asc) { global $currentPage, $member;
 if(!$currentPage) $currentPage = 1;
 $codeLen = strlen($targetCode);
 if($codeLen < 2) return;
 $where_sql = "where view_ox = 1 and left(small_code, $codeLen) = '$targetCode' ";
 $common_sql = "from qpass_exam $where_sql ";
 $count_sql = "select count(*) ".$common_sql;
 /*echo $count_sql;
*/ list($totalLine) = sqlFetchArrayQ($count_sql);
 $startLine = ($currentPage-1) * $viewLine;
 $lineCount = 1;
 /* 제목라인*/ echo "<table width='800' align='center' cellpadding='5' cellspacing='0' style='margin-top:7px' border='0'>";
 echo "<tr height='30'>";
 echo "<td width='35' class='td_border_commonTitle_qpass'>순서</td>";
 echo "<td width='' class='td_border_commonTitle_qpass'>분류</td>";
 echo "<td width='' class='td_border_commonTitle_qpass'>시험명</td>";
 echo "<td width='40' class='td_border_commonTitle_qpass'>문제수</td>";
 echo "<td width='' class='td_border_commonTitle_qpass'>출제일시</td>";
 echo "<td width='80' class='td_border_commonTitle_qpass'>응시하기</td>";
 echo "<td width='80' class='td_border_rightTitle_qpass'>응시결과</td>";
 echo "</tr>";
 if($totalLine == 0) { echo "<tr height='100'><td colspan='7' class='ed' align='center'>등록된 시험이 없습니다.</td></tr>";
  echo "</table>";
 return;
 } $sql = "select uid, small_code, exam_name, reg_time, cat_countTotal ".$common_sql;
 if($asc) $sql .= "order by uid $asc";
 $sql .= " limit $startLine, $viewLine";
 /*echo $sql;
*/ $result = mysql_query($sql);
 $revCount = $totalLine - $startLine;
 while( $row = mysql_fetch_array($result) ) { /* 셀 보드 설정*/ if($lineCount < $viewLine && $revCount > 1) {  $common_style = "td_border_common_qpass";
  $right_style = "td_border_right_qpass";
 } else {  $common_style = "td_border_bottom_qpass";
 $right_style = "td_border_bottomright_qpass";
 }  $bigName = get_bigName( substr($row[small_code], 0,2) );
 $midName = get_midName( substr($row[small_code], 0,4) );
 $smallName = get_smallName($row[small_code]);
 $catText = "$bigName &gt;
 $midName &gt;
 $smallName";
  $sql = "select count(*) from qpass_question where exam_uid = '$row[uid]' ";
 list($questionCount) = sqlFetchArrayQ($sql);
 $regText = substr($row[reg_time], 0,16);
 if($questionCount > 0) $takeExamText = "<a href='qpass_takeExam.php?examUid=$row[uid]'><img src='./img/btn_takeExam.gif' width='57' height='20'></a>";
 else { $takeExamText = "-";
 } /* 응시결과 추출*/ if($member[mb_id]) {  $sql = "select count(*) from qpass_result where mb_id = '$member[mb_id]' and exam_uid = '$row[uid]' ";
 /*echo $sql;
*/ list($resultCount) = sqlFetchArrayQ($sql);
 } if($resultCount > 0) {  $correctCount = get_examCorrectCount($row[uid], $row[cat_countTotal], $member[mb_id]);
 $score = ceil( ($correctCount * 100) / $questionCount );
 $resultText = "$correctCount/$questionCount (".$score."점)";
 } else { $resultText = "<span style='color:#bb8800'>응시전</span>";
 }  echo "<tr height='27'>";
 echo "<td width='40' align='center' class='$common_style'>$revCount</td>";
 echo "<td width='' class='$common_style'>$catText</td>";
 echo "<td width='' class='$common_style'>$row[exam_name]</td>";
 echo "<td width='' align='center' class='$common_style'>$questionCount</td>";
 echo "<td width='100' align='center' class='$common_style'>$regText</td>";
 echo "<td width='80' align='center' class='$common_style'>$takeExamText</td>";
 echo "<td width='80' align='center' class='$right_style'>$resultText</td>";
 echo "</tr>";
 $revCount--;
 $lineCount++;
 } echo "</table>";
 print_qpass_pages($totalLine, $viewLine, $currentPage, "examHome");
 } function print_qpass_pages($total_line, $view_line, $currentPage, $place) { global $view_pages, $bigCode, $midCode, $smallCode, $small_code, $uid;
 if($place == "exam") $parameter_add = "&small_code=$small_code";
 else if($place == "examHome") $parameter_add = "&bigCode=$bigCode&midCode=$midCode&smallCode=$smallCode";
 else if($place) $parameter_add = $place;
 if($view_line) $total_page = ceil($total_line/$view_line);
 if($total_page <= 1) return;
 $page_end = ceil($currentPage/$view_pages) * $view_pages ;
 $page_start = $page_end - $view_pages + 1;
 echo "<table width='100%' cellspacing='0' cellpadding='5' style='margin-top:5px' border='0'><tr><td align='center' style='font-size:12px'>";
 if($page_end > $view_pages) echo "<a href='?currentPage=1{$parameter_add}'>[처음]</a> ";
 $next_current = $page_end-$view_pages;
 if($page_end > $view_pages) echo "<a href='?currentPage=$next_current{$parameter_add}'>[이전]</a>";
 for($i=$page_start;
 $i<=$page_end && $i<=$total_page;
 $i++){ if($i == $currentPage) { echo "<span style='color:#E42101'>$i</span> ";
 } else { echo "<a href='?currentPage=$i{$parameter_add}'>[$i]</a> ";
 } } $next_current = $page_end+1;
 if($page_end < $total_page) echo "<a href='?currentPage=$next_current{$parameter_add}'>[다음]</a>";
 if($page_end < $total_page) echo "<a href='?currentPage=$total_page{$parameter_add}'>[맨끝]</a>";
 echo "</td></tr></table>";
 return;
 } function print_qpass_answerSheet($examUid, $mode) { if($examUid == "") return;
  $sql = "select * from qpass_exam where uid = '$examUid' ";
  $resultExam = mysql_query($sql);
 $rowExam = mysql_fetch_array($resultExam);
 /* 전체 과목수 추출*/ $course_count = $rowExam[cat_countTotal];
 /* 전체 문제수 추출*/ $sql = "select count(*) from qpass_question where exam_uid = '$examUid' ";
 list($question_total) = sqlFetchArrayQ($sql);
 /* 과목별 문제수 추출*/ if($course_count == 1) $question_count[0] = $question_total;
 else {  for($i=0;
 $i < $course_count;
 $i++) { $i_add = $i + 1;
 if($i_add < 10) $i_add = "0".$i_add;
 $cat_subject = $rowExam["cat_title".$i_add];
 $sql = "select count(*) from qpass_question where exam_uid = '$examUid' and cat_index = '$i' ";
 /*echo $sql."<br/>";
*/   list($question_each) = sqlFetchArrayQ($sql);
 $question_count[$i] = $question_each;
 } } $ans_count = 1;
 $max_div = $course_count - 1;
 for($i=0;
 $i <= $max_div;
 $i++) { $i_add = $i + 1;
 if($i_add < 10) $i_add = "0".$i_add;
  $course_name = $rowExam["cat_title".$i_add];
 echo "<div id = 'ans$i' style='display:none;
 width:100%;
 height:100%;
 padding-left:4px'>";
  echo "<table width='100%' height='30' align='center' cellspacing='0' cellpadding='2'><tr><td align='center' style='color:green;
 font-weight:bold;
 border:solid 1px #ccc;
 border-bottom:none'>$course_name</td></tr></table>";
  echo "<table width='100%' align='center' cellspacing='0' cellpadding='2' border='0'>";
 for($j=0;
 $j < $question_count[$i];
 $j++) { /* 과목별 문제수만큼 루프*/ /* 셀 보드 설정*/ if($j < $question_count[$i]-1) {  $common_style = "td_border_common_qpass";
 $right_style = "td_border_right_qpass";
 } else { $common_style = "td_border_bottom_qpass";
 $right_style = "td_border_bottomright_qpass";
 } if($ans_count > $question_total) continue;
 $chooseStyle = get_chooseStyle($examUid, $i, $j);
  echo "<tr height='25'> <td id='ans_num{$ans_count}' width='23' valign='bottom' align='center' class='$common_style' style='padding-bottom:3px;
 font-weight:bold;
 color:green'><a href='javascript:move2question($j)' style='color:green' onfocus='this.blur()'>$ans_count</a></td>";
 if($chooseStyle == 1) {  echo "<td id='ans_td{$ans_count}1' width='20' align='center' class='$common_style'><a href='javascript:answer_check($ans_count, 1)' onfocus='this.blur()'><img id='answer{$ans_count}1' src='./img/num1.gif' align='absmiddle'></td>";
  echo "<td id='ans_td{$ans_count}2' width='20' align='center' class='$common_style'><a href='javascript:answer_check($ans_count, 2)' onfocus='this.blur()'><img id='answer{$ans_count}2' src='./img/num2.gif' align='absmiddle'></td>";
  echo "<td id='ans_td{$ans_count}3' width='20' align='center' class='$common_style'><a href='javascript:answer_check($ans_count, 3)' onfocus='this.blur()'><img id='answer{$ans_count}3' src='./img/num3.gif' align='absmiddle'></td>";
  echo "<td id='ans_td{$ans_count}4' width='20' align='center' class='$right_style'><a href='javascript:answer_check($ans_count, 4)' onfocus='this.blur()'><img id='answer{$ans_count}4' src='./img/num4.gif' align='absmiddle'></td>";
  echo "<td id='ans_td{$ans_count}5' width='20' align='center' class='$right_style'><a href='javascript:answer_check($ans_count, 5)' onfocus='this.blur()'><img id='answer{$ans_count}5' src='./img/num2.gif' align='absmiddle'></td> </tr>";
 } 
 
 else {  echo "<td id='ansInsert_td{$ans_count}' colspan='5' class='$right_style'><input type='text' id='ansInsert_text{$ans_count}' maxlength='10' value='' class='ed' style='width:99%'> <span id='ansInsert_span{$ans_count}' style='display:none'></span></td> </tr>";
 } $ans_count++;
 } echo "</table>";
  echo "<p id='btnFinish{$i}' align='center' style='display:block;
 margin: 20px 0 0 0'><input type='button' value='답안제출' onclick='finish_exam($i);
' style='color:#222222;
 cursor:pointer;
 border:2px outset;
 background-color:#f0f0f0;
 width:65px;
 height:21px;
 padding-top:1px;
 ' onfocus='this.blur()'></p>";
 echo "<p id='resultDisplay{$i}' align='center' style='margin: 20px 0 0 0'></p>";
 echo "</div>";
 } } function get_chooseStyle($examUid, $i, $j) { $sql = "select answer01 from qpass_question where exam_uid = '$examUid' and cat_index = '$i' order by view_index asc, uid asc limit $j, 1";
 /* echo $sql;
 */ list($answer01) = sqlFetchArrayQ($sql);
 /*return 1;
*/ if($answer01) return 1;
 else return 0;
 } function print_qpass_examSheet($examUid, $mode) { if($examUid == "") return;
 global $member;
  $sql = "select * from qpass_exam where uid = '$examUid' ";
  $resultExam = mysql_query($sql);
 $rowExam = mysql_fetch_array($resultExam);
 /* 전체 과목수 추출*/ $course_count = $rowExam[cat_countTotal];
 /* 전체 문제수 추출*/ $sql = "select count(*) from qpass_question where exam_uid = '$examUid' ";
 list($question_total) = sqlFetchArrayQ($sql);
 /* 답안/정답 저장폼 구성*/ $questionCount = 1;
 for($i=0;
 $i < $course_count;
 $i++) { $i_add = $i + 1;
 if($i_add < 10) $i_add = "0".$i_add;
  $cat_subject = $rowExam["cat_title".$i_add];
 $sqlTry = "select try_list{$i_add} from qpass_result where mb_id = '$member[mb_id]' and exam_uid = '$examUid' ";
 /*echo $sqlTry;
*/ $resultTry = mysql_query($sqlTry);
 $rowTry = mysql_fetch_array($resultTry);
 $tryList = explode("|Q|", $rowTry["try_list".$i_add]);
 $tryCountMin = $tryCount - 1;
 $sql = "select count(*) from qpass_question where exam_uid = '$examUid' and cat_index = '$i' ";
 list($cat_questionCount) = sqlFetchArrayQ($sql);
  $sqlReal = "select answer from qpass_question where exam_uid = '$examUid' and cat_index = '$i' order by view_index asc, uid asc";
 /*if($i > 1) echo $sqlReal."<br/>";
*/ $resultReal = mysql_query($sqlReal);
 for($j=0;
 $j < $cat_questionCount;
 $j++) { /*try$questionCount*/ echo "<input type='hidden' id='ans_try{$questionCount}' size='3' value='$tryList[$j]'>";
 echo "<input type='hidden' id='ans_trySame{$questionCount}' size='3' value='$tryList[$j]'>";
 /* 복사본 준비*/  $rowReal = mysql_fetch_array($resultReal);
 $ansReal = $rowReal[answer];
 /*ans$questionCount*/  echo "<input type='hidden' id='ans_real{$questionCount}' size='2' value='$ansReal'>";
  $questionCount++;
 } } /* 과목별 문제수 추출*/ if($course_count == 1) $question_count[0] = $question_total;
 else {  for($i=0;
 $i < $course_count;
 $i++) { $i_add = $i + 1;
 if($i_add < 10) $i_add = "0".$i_add;
 $cat_subject = $rowExam["cat_title".$i_add];
 $sql = "select count(*) from qpass_question where exam_uid = '$examUid' and cat_index = '$i' ";
 /*echo $sql."<br/>";
*/   list($question_each) = sqlFetchArrayQ($sql);
 $question_count[$i] = $question_each;
 } } /* 과목별 구역수 추출*/ for($i=0;
 $i < $course_count;
 $i++) { $five_div[$i] = ceil($question_count[$i] / 5);
 /*echo $five_div[$i]."<br/>";
*/ $max_fiveCount = $five_div[$i] - 1;
 echo "<script>max_five[$i] = '$max_fiveCount';
</script>";
 }  $count = 1;
 $max_div = $course_count - 1;
 for($i=0;
 $i <= $max_div;
 $i++ ) { /* 교시수만큼 루프*/  /* 문제 추출*/ $i_add = $i + 1;
 if($i_add < 10) $i_add = "0".$i_add;
 $cat_subject = $rowExam["cat_title".$i_add];
  $sql = "select * from qpass_question where exam_uid = '$examUid' and cat_index = '$i' order by view_index asc, uid asc";
 $resultQuestion = mysql_query($sql);
 $rowQuestion = mysql_fetch_array($resultQuestion);
  $div_count = 1;
 /* 교시내 구역 카운터*/ for($j=0;
 $j < $five_div[$i];
 $j++ ) { /* 5문제 구역만큼 루프.*/  /*if($member[mb_id] == 'test' && $j==0) echo "i : $i and ".$count;
*/ if($count > $question_total) {  /*echo "<script>document.test_form.end_i.value='$i';
 document.test_form.end_j.value='$j';
</script>";
*/ break;
 } echo "<div id = 'div$i$j' style='display:none;
 width:100%;
 height:100%'>";
 echo "<table width='100%' cellspacing='0' cellpadding='0' style='margin-top:0px;
' border='0'><tr>";
 echo "<td width='50%' valign='top' class='ed' style='padding-top:5px;
'>";
 for($k=0;
 $k < 3;
 $k++ ) { /* 5문제중 좌측 3문제 보이게 처리*/  /*if($k==0) echo "<input type='hidden' id='start$i$j' value='$count' size='3'>";
*/  if($count > $question_total) continue;
 if($div_count > $question_count[$i]) continue;
 /* 과목별 문제수보다 많으면 패스*/  if($rowQuestion[answer01]) $chooseStyle = 1;
 else { $chooseStyle = 0;
 }  echo "<div id='ques_ox{$count}' style='margin:0;
 position:absolute' width='55' height='45'><img src='./img/blank.gif' width='55' height='45'></div>";
   echo "<table width='100%' height='150' cellspacing='0' cellpadding='5' style='margin-bottom:10px;
' border='0'>";
  echo "<tr> <td valign='top' align='right' width='25' class='count_qpass'>{$count}.</td> <td valign='top' class='question01_qpass'> ".nl2br( trim($rowQuestion[question]) )."</td> </tr>";
  if($chooseStyle == 1) {   echo "<tr> <td id='quesitem{$count}1' colspan='2' class='question02_qpass'><a href='javascript:answer_check($count, 1)' onfocus='this.blur()'>① $rowQuestion[answer01]</a></td> </tr>";
   echo "<tr> <td id='quesitem{$count}2' colspan='2' class='question02_qpass'><a href='javascript:answer_check($count, 2)' onfocus='this.blur()'>② $rowQuestion[answer02]</a></td> </tr>";
   echo "<tr> <td id='quesitem{$count}3' colspan='2' class='question02_qpass'><a href='javascript:answer_check($count, 3)' onfocus='this.blur()'>③ $rowQuestion[answer03]</a></td> </tr>";
   echo "<tr> <td id='quesitem{$count}4' colspan='2' class='question02_qpass'><a href='javascript:answer_check($count, 4)' onfocus='this.blur()'>④ $rowQuestion[answer04]</a></td> </tr>";
   echo "<tr> <td id='quesitem{$count}5' colspan='2' class='question02_qpass'><a href='javascript:answer_check($count, 5)' onfocus='this.blur()'>⑤ $rowQuestion[answer05]</a></td> </tr>";
   /*if($rowQuestion[answer05]) echo "<tr> <td colspan='2' class='question02_qpass'>⑤ $rowQuestion[answer05]</td> </tr>";
*/ } else { /* 주관식 */  }  echo "</table>";
    $commentText = "";
  if($rowQuestion[comment]) {   $commentText = nl2br($rowQuestion[comment]);
   echo "<div id='comment{$count}' style='display:none;
 color:blue;
 line-height:1.5;
 padding:15px;
 padding-top:0px;
'><span style='font-weight:bold;
 '>해설 : </span> $commentText</div>";
 }  $count++;
 $div_count++;
  $rowQuestion = mysql_fetch_array($resultQuestion);
 } echo "</td> <td valign='top' class='ed' style='padding-top:5px;
 border-left:none'>";
 for($k=3;
 $k < 5;
 $k++ ) { /* 5문제중 우측 2문제 보이게 처리*/   if($count > $question_total) continue;
 if($div_count > $question_count[$i]) continue;
 /* 과목별 문제수보다 많으면 패스*/  if($rowQuestion[answer01]) $chooseStyle = 1;
 else { $chooseStyle = 0;
 }  echo "<div id='ques_ox{$count}' style='margin:0;
 position:absolute' width='55' height='45'><img src='./img/blank.gif' width='55' height='45'></div>";
  echo "<table width='100%' height='150' cellspacing='0' cellpadding='5' style='margin-bottom:10px;
' border='0'>";
  echo "<tr> <td valign='top' align='right' width='25' class='count_qpass'>{$count}.</td> <td valign='top' class='question01_qpass'>".nl2br( trim($rowQuestion[question]) )."</td> </tr>";
  if($chooseStyle == 1) {   echo "<tr> <td id='quesitem{$count}1' colspan='2' class='question02_qpass'><a href='javascript:answer_check($count, 1)' onfocus='this.blur()'>① $rowQuestion[answer01]</a></td> </tr>";
   echo "<tr> <td id='quesitem{$count}2' colspan='2' class='question02_qpass'><a href='javascript:answer_check($count, 2)' onfocus='this.blur()'>② $rowQuestion[answer02]</a></td> </tr>";
   echo "<tr> <td id='quesitem{$count}3' colspan='2' class='question02_qpass'><a href='javascript:answer_check($count, 3)' onfocus='this.blur()'>③ $rowQuestion[answer03]</a></td> </tr>";
   echo "<tr> <td id='quesitem{$count}4' colspan='2' class='question02_qpass'><a href='javascript:answer_check($count, 4)' onfocus='this.blur()'>④ $rowQuestion[answer04]</a></td> </tr>";
   echo "<tr> <td id='quesitem{$count}5' colspan='2' class='question02_qpass'><a href='javascript:answer_check($count, 5)' onfocus='this.blur()'>⑤ $rowQuestion[answer05]</a></td> </tr>";
   /*if($rowQuestion[answer05]) echo "<tr> <td colspan='2' class='question02_qpass'>⑤ $rowQuestion[answer05]</td> </tr>";
*/ } else { /* 주관식*/ }  echo "</table>";
  if($rowQuestion[comment]) {   $commentText = nl2br($rowQuestion[comment]);
   echo "<div id='comment{$count}' style='display:none;
 color:blue;
 line-height:1.5;
 padding:15px;
 padding-top:0px;
'><span style='font-weight:bold;
 '>해설 : </span> $commentText</div>";
 }  $count++;
 $div_count++;
  $rowQuestion = mysql_fetch_array($resultQuestion);
 } echo "&nbsp;
</td></tr></table>";
 /* 이동 버튼*/ $cat_subject = addslashes($cat_subject);
 echo "<table width='100%' height='50' cellspacing='0' cellpadding='0' border='0'>";
 echo "<tr><td width='50%' align='right' style='padding-right:12px'><input type='button' value='이전' onclick=\"previous_div('$cat_subject', $i, $j)\" class='btn01_qpass' style='width:35px;
 height:21px;
 padding-top:1px' onfocus='this.blur()'></td>";
  echo "<td style='padding-left:10px'><input type='button' value='다음' onclick=\"next_div('$cat_subject', $i, $j)\" class='btn01_qpass' style='width:35px;
 height:21px;
 padding-top:1px' onfocus='this.blur()'></td> </tr>";
 echo "</table>";
 echo "</div>";
 } } } /* delete 그룹*/ function delete_questionUpfile($questionUid) { for($i=0;
 $i <= 5;
 $i++) { $destUrl = "./upfile/qpass{$questionUid}_{$i}";
  if( file_exists($destUrl) ) unlink($destUrl);
 } } function delete_examUpfile($examUid) { $sql = "select uid from qpass_question where exam_uid = '$examUid' ";
 $result = mysql_query($sql);
 while( $row = mysql_fetch_array($result) ) { delete_questionUpfile($row[uid]);
 $sql = "delete from qpass_question where uid = '$row[uid]' ";
 mysql_query($sql);
 } /* 응시기록도 삭제 추가*/ } ?>
